<?php
 /*******************************************************************************
 * @filename: view.ctp
 *
 * @author: immer_baldos
 *
 * @description: products/view view
 *
 * @history:
 *
 *   VERSION   DATE                   BY          NOTES
 *  ---------------------------------------------------------------
 *     1.0     September  9, 2009     immer       initial bake
 *
 *     2.0     September 16, 2009     immer       add role based menus
 *
 ******************************************************************************/
 ?>
<div class="products view">
<h2><?php  __('Product');?></h2>
	<dl><?php $i = 0; $class = ' class="altrow"';?>
		<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Id'); ?></dt>
		<dd<?php if ($i++ % 2 == 0) echo $class;?>>
			<?php echo $product['Product']['id']; ?>
			&nbsp;
		</dd>
		<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Name'); ?></dt>
		<dd<?php if ($i++ % 2 == 0) echo $class;?>>
			<?php echo $product['Product']['name']; ?>
			&nbsp;
		</dd>
		<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Description'); ?></dt>
		<dd<?php if ($i++ % 2 == 0) echo $class;?>>
			<?php echo $product['Product']['description']; ?>
			&nbsp;
		</dd>
		<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Instock'); ?></dt>
		<dd<?php if ($i++ % 2 == 0) echo $class;?>>
			<?php echo $product['Product']['instock']; ?>
			&nbsp;
		</dd>
		<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Sold'); ?></dt>
		<dd<?php if ($i++ % 2 == 0) echo $class;?>>
			<?php echo $product['Product']['sold']; ?>
			&nbsp;
		</dd>
		<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Price'); ?></dt>
		<dd<?php if ($i++ % 2 == 0) echo $class;?>>
			<?php echo $product['Product']['price']; ?>
			&nbsp;
		</dd>
	</dl>
</div>
<div class="actions">
	<ul>
		<li><?php echo $html->link(__('Edit Product', true), array('action' => 'edit', $product['Product']['id'])); ?> </li>
		<li><?php echo $html->link(__('Delete Product', true), array('action' => 'delete', $product['Product']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $product['Product']['id'])); ?> </li>
		<li><?php echo $html->link(__('List Products', true), array('action' => 'index')); ?> </li>
		<li><?php echo $html->link(__('New Product', true), array('action' => 'add')); ?> </li>
		<li><?php
		    if ($_SESSION['Auth']['User']['role'] == "admin" ){
		        echo $html->link(__('List Transactions', true), array('controller' => 'transactions', 'action' => 'index'));
		    }
		    ?> </li>
		<li><?php
		    if ($_SESSION['Auth']['User']['role'] == "admin" ){
		        echo $html->link(__('New Transaction', true), array('controller' => 'transactions', 'action' => 'add'));
		    }
		    ?> </li>
	</ul>
</div>

<?php if ($_SESSION['Auth']['User']['role'] == "admin"):?>
<div class="related">
	<h3><?php __('Related Transactions');?></h3>
	<?php if (!empty($product['Transaction'])):?>
	<table cellpadding = "0" cellspacing = "0">
	<tr>
		<th><?php __('Id'); ?></th>
		<th><?php __('Price'); ?></th>
		<th><?php __('Count'); ?></th>
		<th><?php __('Order Id'); ?></th>
		<th><?php __('Customer Id'); ?></th>
		<th><?php __('Product Id'); ?></th>
		<th class="actions"><?php __('Actions');?></th>
	</tr>
	<?php
		$i = 0;
		foreach ($product['Transaction'] as $transaction):
			$class = null;
			if ($i++ % 2 == 0) {
				$class = ' class="altrow"';
			}
		?>
		<tr<?php echo $class;?>>
			<td><?php echo $transaction['id'];?></td>
			<td><?php echo $transaction['price'];?></td>
			<td><?php echo $transaction['count'];?></td>
			<td><?php echo $transaction['order_id'];?></td>
			<td><?php echo $transaction['customer_id'];?></td>
			<td><?php echo $transaction['product_id'];?></td>
			<td class="actions">
				<?php echo $html->link(__('View', true), array('controller' => 'transactions', 'action' => 'view', $transaction['id'])); ?>
				<?php echo $html->link(__('Edit', true), array('controller' => 'transactions', 'action' => 'edit', $transaction['id'])); ?>
				<?php echo $html->link(__('Delete', true), array('controller' => 'transactions', 'action' => 'delete', $transaction['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $transaction['id'])); ?>
			</td>
		</tr>
	<?php endforeach; ?>
	</table>
<?php endif; ?>

	<div class="actions">
		<ul>
			<li><?php echo $html->link(__('New Transaction', true), array('controller' => 'transactions', 'action' => 'add'));?> </li>
		</ul>
	</div>
<?php endif; ?>
</div>
